<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
	String path = request.getContextPath();
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path + "/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
	<head>
		<title>牌局历史列表</title>
		<meta http-equiv="pragma" content="no-cache">
		<meta http-equiv="cache-control" content="no-cache">
		<meta http-equiv="expires" content="0">
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">

		<link rel="stylesheet" type="text/css"
			href="<%=basePath%>skins/themes/default/easyui.css">
		<link rel="stylesheet" type="text/css"
			href="<%=basePath%>skins/themes/icon.css">
		<link rel="stylesheet" type="text/css"
			href="<%=basePath%>skins/themes/demo.css">
		<script type="text/javascript"
			src="<%=basePath%>skins/jquery-1.7.2.min.js">
</script>
		<script type="text/javascript"
			src="<%=basePath%>skins/jquery.easyui.min.js">
</script>
		<script type="text/javascript"
			src="<%=basePath%>skins/My97DatePicker/WdatePicker.js">
</script>
		<script type="text/javascript">
$(function() {
	$.ajax( {
		type : "post",
		async : false,
		dataType : "json",
		url : '<%=basePath%>dict/insureAmong.action',
		success : function(data) {
			var list = data.dictList;
			$("#insure").append("<option value='0'>请选择</option>");
			for ( var i = 0; i < list.length; i++) {
				$("#insure").append(
						"<option value='" + list[i].dictSn + "' title='"+list[i].dictValue1+"~"+(list[i].dictValue2==-1?'以上':list[i].dictValue2)+"'>"
								+ list[i].dictTitle + "</option>");
			}
		}
	});
	$('body').append('<div id="inningsWindow" class="easyui-dialog" closed="true"></div>');
	$('#data').datagrid( {
		title : '牌局历史列表',
		iconCls : 'icon-save',
		width : 900,
		height : 400,
		nowrap : true,
		striped : true,
		singleSelect : true,
		fitColumns: true, //自动调整各列，用了这个属性，下面各列的宽度值就只是一个比例。
		striped: true, //奇偶行颜色不同
		collapsible : false,
		sortName : 'id',
		loadMsg : '数据正在下载中,请稍等...',
		sortOrder : 'desc',
		remoteSort : false,
		idField : ' inningSn',
		url:"<%=basePath%>innings/query.action", //数据来源
		queryParams:{a:1}, //查询条件
		columns : [ [ {
			field : 'memberName',
			title : '操作员',
			width : 80,
			align : 'center'
		}, {
			field : 'insure',
			title : '投保金额',
			width : 100,
			align : 'center'
		}, {
			field : 'players',
			title : '玩家数',
			width : 80,
			align : 'center'
		}, {
			title : '赢的概率',
			field : 'win',
			width : 65,
			align : 'center',
			formatter : function(val, row){
				if(val > 0){
					var win = val * 100;
					if(win >= 60){
						return "<font color='green'>"+ win +"%</font>";
					} else {
						return "<font color='red'>"+ win +"%</font>";
					}
				}
			}
		}, {
			title : '输的概率',
			field : 'lose',
			width : 65,
			align : 'center',
			formatter : function(val, row){
				if(val > 0){
					var win = val * 100;
					if(win >= 60){
						return "<font color='green'>"+ win +"%</font>";
					} else {
						return "<font color='red'>"+ win +"%</font>";
					}
				}
			}
		}, {
			title : '平的概率',
			field : "tie",
			width : 65,
			align : 'center',
			formatter : function(val, row){
				if(val > 0){
					var win = val * 100;
					if(win >= 60){
						return "<font color='green'>"+ win +"%</font>";
					} else {
						return "<font color='red'>"+ win +"%</font>";
					}
				}
			}
		}, {
			title : '对方平的概率',
			field : "oppTie",
			width : 80,
			align : 'center',
			formatter : function(val, row){
				if(val > 0){
					var win = val * 100;
					if(win >= 60){
						return "<font color='green'>"+ win +"%</font>";
					} else {
						return "<font color='red'>"+ win +"%</font>";
					}
				}
			}
		}, {
			title : '赔率',
			field : "odds",
			width : 80,
			align : 'center'
		}, {
			field : 'createTime',
			title : '创建时间',
			width : 130,
			align : 'center'
		}, {
			field : 'createIp',
			title : '创建地点',
			width : 100,
			align : 'center'
		} ] ],
		pagination : true,
		rownumbers : true,
		toolbar : [ {
			id : 'btnEdit',
			text : '编辑',
			iconCls : 'icon-edit',
			handler : function() {
				$('#btnEdit').linkbutton();
				edit();
			}
		}, {
			id : 'btnRemove',
			text : '删除',
			iconCls : 'icon-remove',
			handler : function() {
				$('#btnRemove').linkbutton();
				remove();
			}
		}, {
			id : 'btnExcel',
			text : '导出Excel',
			iconCls : 'icon-excel',
			handler : function() {
				$('btnExcel').linkbutton();
				exprot();
			}
		} ],
		loadFilter : function(data){
			if(data.success){
				return data.pageBean;
			}
			return null;
		},
		onLoadSuccess:function(){
			$('#data').datagrid('clearSelections'); //一定要加上这一句，要不然datagrid会记住之前的选择状态，删除时会出问题
		}
	});
 	var p = $('#data').datagrid('getPager');
	if (p) {
	 	$(p).pagination( {
	 		displayMsg : "当前显示从{from}到{to}共{total}记录"
	 	});
	}
});

// 导出文件
function exprot(){
	var params = "";
	var fields = $('#queryForm').serializeArray(); //自动序列化表单元素为JSON对象
	$.each(fields, function(i, field){
		if(null != field.value && field.value.length > 0){
			params += "&" + field.name+"="+field.value;
		}
	}); 
	params = params.replace("&","?");
	$('body').append('<iframe scrolling="yes" frameborder="0" src="<%=basePath%>innings/exprot.action" style="width:0px;height:0px;"></iframe>');
	//	$("#download").remove();
}

function edit() {
	var row = $('#data').datagrid('getSelected');
	if (row) {
		inputWindows("编辑[ <font color='red'>"+row.createTime+"</font> ]时间点的牌局记录", "icon-edit", '<%=basePath%>innings/detail.action?inningSn='+row.inningSn);
	} else {
		$.messager.alert("温馨提示", "请选择一行！");
	}
}

function remove(){
	var row = $('#data').datagrid('getSelected');
	if (row) {
		$.messager.confirm('删除确认','你确定要删除[ <font color="red">'+row.createTime+'</font> ]时间点的有关数据?',function(r){  
		    if (r){  
				$.ajax( {
					type : "POST",
					async : false,
					dataType : "json",
					url : '<%=basePath%>innings/delete.action?inningSn='+ row.inningSn,
					success : function(result) {
						if (result.success == true) {
							$.messager.alert('温馨提示', result.message);
							$('#data').datagrid('reload');
						} else {
							$.messager.alert('温馨提示', result.message);
						}
					}
				}); 
			}
	    });  
	} else {
		$.messager.alert("温馨提示", "请选择一行！");
	}
}
function inputWindows(title, icon, href) {
	$('#inningsWindow').window( {
		title : title,
		iconCls : icon == undefined ? "icon-save" : icon,
		width : 400,
		height : 200, 
		content: '<iframe scrolling="yes" frameborder="0" src="' + href + '" style="width:100%;height:98%;"></iframe>',
		collapsible : false,
		minimizable : false,
		maximizable : false,
		closed : false,
		resizable : false,
		modal : true
	});
}

function searchInnings(){
	var params = $('#data').datagrid('options').queryParams; //先取得 datagrid 的查询参数
	var fields = $('#queryForm').serializeArray(); //自动序列化表单元素为JSON对象
	$.each(fields, function(i, field){
		params[field.name] = field.value; //设置查询参数
	}); 
	$('#data').datagrid('reload'); //设置好查询参数 reload 一下就可以了
}

//清空查询条件
function clearForm(){
	$('#queryForm').form('clear');
 	searchInnings();
}
</script>
	</head>
	<body>
		<form id="queryForm" style="text-align: center;">
			<table width="100%">
				<tr>
					<td>
						操作员：
						<input type="text" name="innings.memberName" style="width: 200px" />
					</td>
					<td>
						投保金额：
						<select id="insure" class="easyui-validatebox"
							name="insureAmong" style="width: 260px" /></select>
					</td>
					<td align="center">
						<a href="javascript:void(0);" onclick="clearForm();"
							class="easyui-linkbutton" iconCls="icon-search">清空</a>
					</td>
				</tr>
				<tr>
					<td colspan="2">
						游戏时间：
						<input id="beginTime" name="beginTime" style="width: 200px"
							class="Wdate"
							onclick="WdatePicker({maxDate:'#F{$dp.$D(\'endTime\')}'})">
						-
						<input id="endTime" name="endTime" style="width: 200px"
							class="Wdate"
							onclick="WdatePicker({minDate:'#F{$dp.$D(\'beginTime\')}',maxDate:'%y-%M-%d'})">
					</td>
					<td align="center">
						<a href="javascript:void(0);" onclick="searchInnings();"
							class="easyui-linkbutton" iconCls="icon-search">查询</a>
					</td>
				</tr>
			</table>
		</form>
		<div style="padding: 10">
			<table id="data"></table>
		</div>
	</body>
</html>
